<?php
/**
 * 		Copyright:SmartCome
 * 		  WebSite:www.SmartCome.com
 *             QQ:2811931192
 */
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}
function get_post_by_type($type,$n,$order,$forbide){
	switch($type){
		case   'new':$type='dateline';break;
		case   'hot':$type='replies';break;
		case  'view':$type='views';break;
		case 'newreply':$type='lastpost';break;
		default:return array();
		}
	$n=(int)$n;$orderstr="asc";
	if($order==1)$orderstr="desc";
	foreach($forbide as $k=>$fid){
	if((int)($fid))$forumsql=$forumsql.' and fid!='.$fid;}
	$sql="SELECT tid,fid,author,subject,dateline,replies,views,lastpost FROM ".DB::table('forum_thread').
	" where closed=0".$forumsql." order by ".$type." ".$orderstr." limit ".$n;
	$querys=DB::query($sql);$post=array();
	while($mood = DB::fetch($querys)) {
	if($mood['fid']){
	$fsql=	"SELECT name FROM ".DB::table('forum_forum')." where fid=".$mood['fid'];
	$fquery=DB::query($fsql);$fmood = DB::fetch($fquery);$mood['fname']=$fmood['name'];}	
	$mood['dateline']=date("m-d",$mood['dateline']);
	$mood['lastpost']=date("m-d",$mood['lastpost']);
    $post[]=$mood;
    }
	return $post;
	}
function get_pic($n,$atturl){
	$n=(int)$n;
	$sql="SELECT tid,attachment FROM ".DB::table('forum_threadimage').
	" order by tid DESC limit ".$n;
	$querys=DB::query($sql);$pic=array();
	while($mood = DB::fetch($querys)) {
	$mood['attachment']=$atturl."forum/".$mood['attachment'];
	if(!(fopen($mood['attachment'],"r")))continue;
	$pic[]=$mood;
    }
	foreach($pic as $k=>$v){
	$sql="SELECT subject FROM ".DB::table('forum_thread')." where tid=".$v['tid'];
	$query=DB::query($sql);
	$mood = DB::fetch($query);
	$pic[$k]['url']="forum.php?mod=viewthread&tid=".$v['tid'];
	$pic[$k]['subject']=$mood['subject'];
		}
	return $pic;	
		}
	function get_first_main($tid,$atturl){
		   if(!$tid)return array();
			$post=DB::fetch_first("SELECT tid,subject,message,dateline FROM ".DB::table('forum_post')." where tid=".$tid);
			$postimg=DB::fetch_first("SELECT tid,attachment FROM ".DB::table('forum_threadimage')." where tid=".$tid);
			if($postimg)$post['img']=$atturl."forum/".$postimg['attachment'];
			else $post['img']='';
			require_once libfile('function/discuzcode');
			$post['dateline']=date("Y-m-d",$post['dateline']);
            $post['message']=cutstr(discuzcode($post['message']),108);
			return $post;
			}		
	?>